<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\UserDiy;

/**
 * UserDiySearch represents the model behind the search form about `backend\models\UserDiy`.
 */
class UserDiySearch extends UserDiy
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'user_id', 'diy_id', 'img_small_id', 'img_thumb_id', 'img_url_id', 'create_time', 'from_uid', 'from_id'], 'integer'],
            [['name', 'tips'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = UserDiy::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'user_id' => $this->user_id,
            'diy_id' => $this->diy_id,
            'img_small_id' => $this->img_small_id,
            'img_thumb_id' => $this->img_thumb_id,
            'img_url_id' => $this->img_url_id,
            'create_time' => $this->create_time,
            'from_uid' => $this->from_uid,
            'from_id' => $this->from_id,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'tips', $this->tips]);

        return $dataProvider;
    }
}
